Skip to main content

Repository Management

Repository Management nima?โ€‹

Repository Management - bu Git repositorylaringizni tartibli, xavfsiz va samarali tarzda boshqarishdir.

Bu xuddi kutubxonani tartibda saqlash kabi - har bir kitob o'z joyida, topish oson, tartib-qoidalar bor! ๐Ÿ“š

Repository Structureโ€‹

1. Standard Project Structureโ€‹

my-project/
โ”œโ”€โ”€ .github/ # GitHub specific files
โ”‚ โ”œโ”€โ”€ workflows/ # CI/CD workflows
โ”‚ โ”œโ”€โ”€ ISSUE_TEMPLATE/ # Issue templates
โ”‚ โ””โ”€โ”€ PULL_REQUEST_TEMPLATE.md
โ”œโ”€โ”€ .gitlab/ # GitLab specific
โ”‚ โ””โ”€โ”€ merge_request_templates/
โ”œโ”€โ”€ docs/ # Documentation
โ”‚ โ”œโ”€โ”€ README.md
โ”‚ โ”œโ”€โ”€ API.md
โ”‚ โ””โ”€โ”€ DEPLOYMENT.md
โ”œโ”€โ”€ src/ # Source code
โ”‚ โ”œโ”€โ”€ components/
โ”‚ โ”œโ”€โ”€ services/
โ”‚ โ””โ”€โ”€ utils/
โ”œโ”€โ”€ tests/ # Test files
โ”‚ โ”œโ”€โ”€ unit/
โ”‚ โ”œโ”€โ”€ integration/
โ”‚ โ””โ”€โ”€ e2e/
โ”œโ”€โ”€ docker/ # Docker files
โ”‚ โ”œโ”€โ”€ Dockerfile
โ”‚ โ”œโ”€โ”€ docker-compose.yml
โ”‚ โ””โ”€โ”€ .dockerignore
โ”œโ”€โ”€ k8s/ # Kubernetes manifests
โ”‚ โ”œโ”€โ”€ deployment.yaml
โ”‚ โ”œโ”€โ”€ service.yaml
โ”‚ โ””โ”€โ”€ ingress.yaml
โ”œโ”€โ”€ scripts/ # Build/deployment scripts
โ”‚ โ”œโ”€โ”€ build.sh
โ”‚ โ”œโ”€โ”€ deploy.sh
โ”‚ โ””โ”€โ”€ test.sh
โ”œโ”€โ”€ .gitignore # Git ignore rules
โ”œโ”€โ”€ .env.example # Environment template
โ”œโ”€โ”€ package.json # Dependencies (Node.js)
โ”œโ”€โ”€ requirements.txt # Dependencies (Python)
โ”œโ”€โ”€ README.md # Project documentation
โ”œโ”€โ”€ LICENSE # License file
โ””โ”€โ”€ CHANGELOG.md # Version history

2. Monorepo Structureโ€‹

company-monorepo/
โ”œโ”€โ”€ apps/ # Applications
โ”‚ โ”œโ”€โ”€ web-app/
โ”‚ โ”œโ”€โ”€ mobile-app/
โ”‚ โ””โ”€โ”€ admin-panel/
โ”œโ”€โ”€ packages/ # Shared packages
โ”‚ โ”œโ”€โ”€ ui-components/
โ”‚ โ”œโ”€โ”€ utils/
โ”‚ โ””โ”€โ”€ api-client/
โ”œโ”€โ”€ services/ # Microservices
โ”‚ โ”œโ”€โ”€ user-service/
โ”‚ โ”œโ”€โ”€ payment-service/
โ”‚ โ””โ”€โ”€ notification-service/
โ”œโ”€โ”€ infrastructure/ # DevOps files
โ”‚ โ”œโ”€โ”€ terraform/
โ”‚ โ”œโ”€โ”€ ansible/
โ”‚ โ””โ”€โ”€ k8s/
โ””โ”€โ”€ tools/ # Development tools
โ”œโ”€โ”€ linting/
โ”œโ”€โ”€ testing/
โ””โ”€โ”€ ci-cd/

Repository Configurationโ€‹

1. Git Configurationโ€‹

Global config:โ€‹

# User information
git config --global user.name "Sizning Ismingiz"
git config --global user.email "email@company.com"

# Editor
git config --global core.editor "code --wait"

# Default branch
git config --global init.defaultBranch main

# Helpful aliases
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.unstage "reset HEAD --"
git config --global alias.last "log -1 HEAD"
git config --global alias.visual "!gitk"

Repository config:โ€‹

# Local repository settings
git config user.email "work@company.com"
git config core.autocrlf false
git config core.filemode false

2. .gitignore Configurationโ€‹

Node.js project:โ€‹

# Dependencies
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs
lib-cov

# Coverage directory used by tools like istanbul
coverage/
*.lcov

# nyc test coverage
.nyc_output

# Dependency directories
jspm_packages/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test
.env.local
.env.production

# Build outputs
dist/
build/

# IDE files
.vscode/
.idea/
*.swp
*.swo
*~

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

Python project:โ€‹

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Virtual environments
venv/
ENV/
env/
.venv/

# IDE
.vscode/
.idea/
*.swp
*.swo

# Environment variables
.env
.env.local
.env.production

3. Git Hooksโ€‹

Pre-commit hook:โ€‹

#!/bin/sh
# .git/hooks/pre-commit

echo "๐Ÿ” Running pre-commit checks..."

# Check for debugging statements
if grep -r "console.log\|debugger\|pdb.set_trace" src/; then
echo "โŒ Debug statements found. Please remove them."
exit 1
fi

# Run linting
echo "๐Ÿงน Running linter..."
npm run lint
if [ $? -ne 0 ]; then
echo "โŒ Linting failed. Please fix the issues."
exit 1
fi

# Run tests
echo "๐Ÿงช Running tests..."
npm test
if [ $? -ne 0 ]; then
echo "โŒ Tests failed. Please fix the tests."
exit 1
fi

echo "โœ… All pre-commit checks passed!"
exit 0

Commit-msg hook:โ€‹

#!/bin/sh
# .git/hooks/commit-msg

# Check commit message format
commit_regex='^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?: .{1,50}'

if ! grep -qE "$commit_regex" "$1"; then
echo "โŒ Invalid commit message format!"
echo "Format: type(scope): description"
echo "Example: feat(auth): add login functionality"
echo ""
echo "Types: feat, fix, docs, style, refactor, test, chore"
exit 1
fi

echo "โœ… Commit message format is valid!"

Access Control va Permissionsโ€‹

1. GitHub Repository Settingsโ€‹

Collaborators management:โ€‹

# .github/settings.yml
repository:
name: my-project
description: Project description
homepage: https://example.com
topics: [javascript, react, nodejs]
private: false

# Features
has_issues: true
has_projects: true
has_wiki: false
has_downloads: true

# Settings
default_branch: main
allow_squash_merge: true
allow_merge_commit: false
allow_rebase_merge: true
delete_branch_on_merge: true

# Branch protection
branches:
- name: main
protection:
required_status_checks:
strict: true
contexts: [ci/tests, ci/build]
enforce_admins: true
required_pull_request_reviews:
required_approving_review_count: 2
dismiss_stale_reviews: true
require_code_owner_reviews: true
restrictions:
users: []
teams: [team-leads]

Teams va permissions:โ€‹

# Team structure
teams:
- name: backend-team
permission: push
members:
- dev1
- dev2

- name: frontend-team
permission: push
members:
- dev3
- dev4

- name: devops-team
permission: admin
members:
- devops1
- devops2

2. CODEOWNERS Fileโ€‹

# .github/CODEOWNERS

# Global owners
* @team-leads @senior-developers

# Frontend
/frontend/ @frontend-team
*.js @frontend-team
*.vue @frontend-team
*.css @ui-designers

# Backend
/backend/ @backend-team
*.py @backend-team
*.go @backend-team

# DevOps
/docker/ @devops-team
/k8s/ @devops-team
/.github/workflows/ @devops-team
/terraform/ @infra-team

# Documentation
/docs/ @tech-writers @team-leads
README.md @team-leads

# Configuration
*.json @backend-team @devops-team
*.yaml @devops-team
*.yml @devops-team

# Database
/migrations/ @database-team @backend-team
*.sql @database-team

Repository Templatesโ€‹

1. GitHub Template Repositoryโ€‹

Template yaratish:

# Template repository settings
Settings โ†’ Template repository โœ…

# Template structure
template-repo/
โ”œโ”€โ”€ .github/
โ”‚ โ”œโ”€โ”€ workflows/
โ”‚ โ”‚ โ”œโ”€โ”€ ci.yml
โ”‚ โ”‚ โ””โ”€โ”€ cd.yml
โ”‚ โ”œโ”€โ”€ ISSUE_TEMPLATE/
โ”‚ โ”‚ โ”œโ”€โ”€ bug_report.md
โ”‚ โ”‚ โ””โ”€โ”€ feature_request.md
โ”‚ โ””โ”€โ”€ PULL_REQUEST_TEMPLATE.md
โ”œโ”€โ”€ src/
โ”œโ”€โ”€ tests/
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ package.json

2. Issue Templatesโ€‹

<!-- .github/ISSUE_TEMPLATE/bug_report.md -->
---
name: Bug Report
about: Create a report to help us improve
title: '[BUG] '
labels: bug
assignees: ''
---

## ๐Ÿ› Bug Description
A clear description of what the bug is.

## ๐Ÿ”„ Steps to Reproduce
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

## โœ… Expected Behavior
What you expected to happen.

## โŒ Actual Behavior
What actually happened.

## ๐Ÿ“ฑ Environment
- OS: [e.g. macOS, Windows, Linux]
- Browser: [e.g. Chrome, Safari]
- Version: [e.g. 22]

## ๐Ÿ“Ž Additional Context
Add any other context about the problem here.

3. Pull Request Templateโ€‹

<!-- .github/PULL_REQUEST_TEMPLATE.md -->
## ๐Ÿ“ Description
Brief description of changes made.

## ๐Ÿ”— Related Issue
Fixes #(issue number)

## ๐Ÿงช Testing
- [ ] Unit tests pass
- [ ] Integration tests pass
- [ ] Manual testing completed

## ๐Ÿ“‹ Checklist
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] No breaking changes
- [ ] Tests added/updated

## ๐Ÿ“ธ Screenshots (if applicable)
Add screenshots here.

## ๐Ÿš€ Deployment Notes
Any special deployment considerations.

Repository Maintenanceโ€‹

1. Regular Cleanupโ€‹

Delete merged branches:โ€‹

# Local branches cleanup
git branch --merged main | grep -v main | xargs -n 1 git branch -d

# Remote branches cleanup
git remote prune origin

# Delete local tracking branches
git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D

Large files cleanup:โ€‹

# Find large files
git rev-list --objects --all |
git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' |
sed -n 's/^blob //p' |
sort --numeric-sort --key=2 |
tail -10

# Remove large files from history
git filter-branch --tree-filter 'rm -f large-file.zip' HEAD
git push origin --force --all

2. Archive Strategyโ€‹

# Repository lifecycle
active: 2 years
maintenance: 1 year
archived: indefinite

# Archive checklist:
- [ ] Final documentation update
- [ ] Dependencies security scan
- [ ] Backup important data
- [ ] Update README with archive notice
- [ ] Set repository to read-only

3. Backup Strategyโ€‹

# Automated backup script
#!/bin/bash

BACKUP_DIR="/backups/git-repos/$(date +%Y-%m-%d)"
mkdir -p "$BACKUP_DIR"

# Clone with all branches and tags
git clone --mirror git@github.com:company/repo.git "$BACKUP_DIR/repo.git"

# Backup issues and PRs (GitHub API)
curl -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/company/repo/issues?state=all" \
> "$BACKUP_DIR/issues.json"

# Compress backup
tar -czf "$BACKUP_DIR.tar.gz" "$BACKUP_DIR"

Repository Analyticsโ€‹

1. Metrics Trackingโ€‹

# Commit frequency
git log --oneline --since="1 month ago" | wc -l

# Contributors
git shortlog -sn --since="1 month ago"

# Code churn
git log --stat --since="1 month ago" | grep "file changed" |
awk '{added+=$4; deleted+=$6} END {print "Added: " added " Deleted: " deleted}'

# Most active files
git log --name-only --pretty=format: | sort | uniq -c | sort -nr | head -10

2. Health Monitoringโ€‹

# Repository health checks
health_check:
- recent_commits: true
- active_contributors: > 2
- test_coverage: > 80%
- security_vulnerabilities: 0
- outdated_dependencies: < 5
- documentation_updated: < 30_days

Multi-Repository Managementโ€‹

1. Git Submodulesโ€‹

# Add submodule
git submodule add https://github.com/company/shared-lib.git lib/shared

# Initialize submodules
git submodule init
git submodule update

# Update submodules
git submodule update --remote

# Clone with submodules
git clone --recursive https://github.com/company/main-project.git

2. Git Subtreesโ€‹

# Add subtree
git subtree add --prefix=lib/shared https://github.com/company/shared-lib.git main

# Update subtree
git subtree pull --prefix=lib/shared https://github.com/company/shared-lib.git main

# Push changes back
git subtree push --prefix=lib/shared https://github.com/company/shared-lib.git main

3. Monorepo Toolsโ€‹

// lerna.json
{
"version": "independent",
"npmClient": "npm",
"command": {
"publish": {
"conventionalCommits": true
},
"bootstrap": {
"ignore": "component-*",
"npmClientArgs": ["--no-package-lock"]
}
},
"packages": ["packages/*"]
}

Best Practicesโ€‹

1. Securityโ€‹

  • โœ… Repository secrets scan qiling
  • โœ… Branch protection rules o'rnating
  • โœ… 2FA enable qiling
  • โœ… Access permissions regularly review qiling
  • โœ… Sensitive data ni environment variables da saqlang

2. Organizationโ€‹

  • โœ… Consistent naming conventions ishlatang
  • โœ… Clear documentation yozing
  • โœ… Regular cleanup qiling
  • โœ… Archive old repositories
  • โœ… Template repository yarating

3. DevOps Integrationโ€‹

  • โœ… CI/CD pipeline sozlang
  • โœ… Automated testing qo'shing
  • โœ… Quality gates o'rnating
  • โœ… Monitoring va alerting sozlang
  • โœ… Backup strategy implement qiling

Xulosaโ€‹

Repository Management - bu dasturlash loyihasining poydevoridir:

โœ… Organization - tartibli tuzilish โœ… Security - xavfsiz access control
โœ… Collaboration - samarali hamkorlik โœ… Maintenance - doimiy parvarish โœ… Automation - avtomatik jarayonlar

DevOps engineer sifatida repository managementni yaxshilash orqali butun development lifecycle ni optimize qilishingiz va jamoangizning productivligini oshirishingiz mumkin!